<?php
/**
 * signup.php
 * Script to create a FooVision account
 *
 * $Id: signup.php 65 2007-09-22 01:02:43Z jonathan.hernandez $
 *
 * TODO: Ajaxify available username
 */
require_once "config/config.php";
require_once "include/FooModel.php";
require_once "include/FooTZ.php";
require_once "include/FooSmarty.php";
require_once "libraries/recaptcha/recaptchalib.php";
$fv = new FooModel($conf);
$s  = new FooSmarty($conf['smarty']);
$excMsg = '';

if (isset($_POST['action']) && $_POST['action'] == 'signup') {
    $username = $_POST['username'];
    $password = $_POST['password'];
    $email    = $_POST['email'];
    $node     = $_POST['node'];
    $location = $_POST['location'];
    $timezone = $_POST['tz'];
    try {
        $fv->newUser($username, $password, $email, $node, $location, $timezone);
    } catch (FooException $e) {
        $excMsg = $e->getMessage();
        switch ($e->getCode()) {
            case FOOEXC_NOTIMPLEMENTED: 
                // Do nothing
                break;
        }
    }
}

$s->assign('exception', $excMsg);

// Timezones
$s->assign('zones', FooTZ::get());
$zone = date_default_timezone_get();
$s->assign('zone', $zone);

// Recaptcha
$publickey = $conf['recaptcha_public_key']; 
$s->assign('recaptcha', recaptcha_get_html($publickey));

$s->display('signup.tpl');
